/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package formularios;

import controlo.ControloEmpregados;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import modelo.ModeloTabela;
import modelo.Modelo_empregados;
import utilizador_bd.ConectBD;

/**
 *
 * @author Daniel
 */
public class Empregados extends javax.swing.JFrame {
    ConectBD conect = new ConectBD();
    ConectBD conectEmp = new ConectBD();
    private  String SQL;

    /**
     * Creates new form Empregados
     */
    public Empregados() {
        initComponents();
        conect.conexao();
        
        
        
        conectEmp.conexao();
        
        preencherTabela("select * from empregados inner join funcao on empregados.funcao = funcao.id_funcao");

        conect.executaSQL("select * from funcao order by descricao");
        jComboBox1funcoes.removeAllItems();
        try {
            conect.re.first();
            do{
                jComboBox1funcoes.addItem(conect.re.getString("descricao"));
            }while (conect.re.next());
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(rootPane, "Erro na combo!"+ex);
        }

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTextField6 = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTextArea2 = new javax.swing.JTextArea();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jTextFieldbi = new javax.swing.JTextField();
        jTextFieldmorada = new javax.swing.JTextField();
        jTextFieldnacionalidade = new javax.swing.JTextField();
        jTextFieldnrcont = new javax.swing.JTextField();
        jTextFieldestado = new javax.swing.JTextField();
        jTextFieldlogin = new javax.swing.JTextField();
        jTextFieldpass = new javax.swing.JTextField();
        jButton1novo = new javax.swing.JButton();
        jButton2guardar = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableempre = new javax.swing.JTable();
        jTextFieldnsegsocial = new javax.swing.JTextField();
        jTextFieldconselho = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jComboBox1funcoes = new javax.swing.JComboBox();
        jTextFieldnome = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2ultimo = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        jTextField6.setText("jTextField6");

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane2.setViewportView(jTextArea1);

        jTextArea2.setColumns(20);
        jTextArea2.setRows(5);
        jScrollPane3.setViewportView(jTextArea2);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("cadastrar_empregados");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel2.setText("Nome:");

        jLabel3.setText("BI:");

        jLabel4.setText("Morada:");

        jLabel5.setText("Nacionalidade:");

        jLabel6.setText("NrContrib:");

        jLabel7.setText("Nrº SegSocial:");

        jLabel8.setText("Estadocivi:");

        jLabel9.setText("Login:");

        jLabel10.setText("Pass:");

        jButton1novo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/add.png"))); // NOI18N
        jButton1novo.setText("Novo");
        jButton1novo.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jButton1novo.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        jButton1novo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1novoActionPerformed(evt);
            }
        });

        jButton2guardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/folder_accept.png"))); // NOI18N
        jButton2guardar.setText("Guardar");
        jButton2guardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2guardarActionPerformed(evt);
            }
        });

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/note_edit.png"))); // NOI18N
        jButton3.setText("Editar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/remove.png"))); // NOI18N
        jButton4.setText("Eliminar");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/repeat.png"))); // NOI18N
        jButton5.setText("Logout");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jTableempre.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTableempre);

        jLabel11.setText("Conselho:");

        jLabel12.setText("Função");

        jComboBox1funcoes.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBox1funcoes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1funcoesActionPerformed(evt);
            }
        });

        jTextFieldnome.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldnomeActionPerformed(evt);
            }
        });

        jButton1.setText("seguinte");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2ultimo.setText("ultimo");
        jButton2ultimo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ultimoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jButton1)
                            .addComponent(jButton1novo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton2ultimo)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(43, 43, 43)
                                .addComponent(jButton2guardar, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton3)
                                .addGap(18, 18, 18)
                                .addComponent(jButton4)
                                .addGap(18, 18, 18)
                                .addComponent(jButton5))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel7)
                            .addGap(18, 18, 18)
                            .addComponent(jTextFieldnsegsocial, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel11)
                                    .addComponent(jLabel10))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jTextFieldpass, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(jPanel1Layout.createSequentialGroup()
                                            .addComponent(jLabel12)
                                            .addGap(38, 38, 38)
                                            .addComponent(jComboBox1funcoes, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addComponent(jTextFieldconselho, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addGap(52, 52, 52)
                                .addComponent(jLabel9)
                                .addGap(18, 18, 18)
                                .addComponent(jTextFieldlogin, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel8)
                            .addGap(18, 18, 18)
                            .addComponent(jTextFieldestado, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel3))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jTextFieldbi, javax.swing.GroupLayout.DEFAULT_SIZE, 148, Short.MAX_VALUE)
                                    .addComponent(jTextFieldnome)))
                            .addComponent(jTextFieldmorada, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldnacionalidade, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addGap(18, 18, 18)
                                .addComponent(jTextFieldnrcont, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(376, 376, 376)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 590, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel7)
                    .addComponent(jTextFieldnsegsocial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldnome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel8)
                    .addComponent(jTextFieldbi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldestado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel9)
                    .addComponent(jTextFieldmorada, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldlogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jTextFieldnacionalidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldpass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldconselho, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel11))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel12)
                            .addComponent(jComboBox1funcoes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(jTextFieldnrcont, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton1)
                            .addComponent(jButton2ultimo))))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton5)
                    .addComponent(jButton4)
                    .addComponent(jButton3)
                    .addComponent(jButton2guardar, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1novo, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(0, 153, 204));
        jLabel1.setText("Formulário de Empregados");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 254, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(179, 179, 179))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(30, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(29, 29, 29))
        );

        setSize(new java.awt.Dimension(686, 595));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2guardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2guardarActionPerformed
       
try {
        Modelo_empregados emp = new Modelo_empregados();
        
        
        emp.setNome(jTextFieldnome.getText());
        emp.setBi(jTextFieldbi.getText());
        emp.setConcelho(jTextFieldconselho.getText());
        emp.setEstadocivil(jTextFieldestado.getText());
        emp.setLogin(jTextFieldlogin.getText());
        emp.setMorada(jTextFieldmorada.getText());
        emp.setNacionalidade(jTextFieldnacionalidade.getText());
        emp.setNrcontribuinte(jTextFieldnrcont.getText());
        emp.setPalavrapasse(jTextFieldpass.getText());
        emp.setSegsocial(jTextFieldnsegsocial.getText());


        conect.executaSQL("select * from funcao where descricao='"+jComboBox1funcoes.getSelectedItem()+"'");
        conect.re.first();
        
        emp.setFuncao(conect.re.getString("id_funcao"));
        
        ControloEmpregados control = new ControloEmpregados();
           
            control.Inserirempregados(emp);
            
      preencherTabela("select * from empregados inner join funcao on empregados.funcao = funcao.id_funcao");

       } catch (SQLException ex) {
            Logger.getLogger(Empregados.class.getName()).log(Level.SEVERE, null, ex);
       }
    }//GEN-LAST:event_jButton2guardarActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        try {
            PreparedStatement pft;
            pft = conect.con.prepareStatement("delete from empregados where bi='" +jTextFieldbi.getText()+"'");
            pft.executeUpdate();
            
            JOptionPane.showMessageDialog(rootPane, "Eliminado com sucesso:");
        } catch (SQLException ex) {
           JOptionPane.showMessageDialog(rootPane, "Erro na inserção!\n Erro:" +ex.getMessage());
        }
            
    }//GEN-LAST:event_jButton4ActionPerformed

    
    
    
    public void preencherTabela(String SQL){
        ArrayList dados = new ArrayList();
        
        String [] Colunas = new String[]{"Nome", "BI", "Conselho", "EstadoCivil", "Função", "Morada","Nacionalidade","NrContribuinte","SegSocial"};
        
        conect.executaSQL(SQL);
          try {
              conect.re.first();
              
                do{
         dados.add(new Object[]{conect.re.getString("nome"),conect.re.getString("bi"),conect.re.getString("concelho"),conect.re.getString("estadocivil"),conect.re.getString("descricao"),conect.re.getString("morada"),conect.re.getString("nacionalidade"),conect.re.getString("nrcontribuinte"),conect.re.getString("segsocial")});
     } while(conect.re.next());
     
          } catch (SQLException ex) {
           JOptionPane.showMessageDialog(null, "Erro no array!\n Erro:" +ex.getMessage());
          }
          
        ModeloTabela modelo  = new ModeloTabela(dados, Colunas);
     
     jTableempre.setModel(modelo);
     jTableempre.getColumnModel().getColumn(0).setPreferredWidth(110);
     jTableempre.getColumnModel().getColumn(0).setResizable(false);
     jTableempre.getColumnModel().getColumn(1).setResizable(false);
     jTableempre.getColumnModel().getColumn(1).setPreferredWidth(110);
     jTableempre.getColumnModel().getColumn(2).setResizable(false);
     jTableempre.getColumnModel().getColumn(2).setPreferredWidth(110);
     jTableempre.getColumnModel().getColumn(3).setResizable(false);
     jTableempre.getColumnModel().getColumn(3).setPreferredWidth(110);
     jTableempre.getColumnModel().getColumn(4).setResizable(false);
     jTableempre.getColumnModel().getColumn(4).setPreferredWidth(110);
     jTableempre.getColumnModel().getColumn(5).setResizable(false);
     jTableempre.getColumnModel().getColumn(5).setPreferredWidth(110);
     jTableempre.getColumnModel().getColumn(6).setResizable(false);
     jTableempre.getColumnModel().getColumn(6).setPreferredWidth(110);
     jTableempre.getColumnModel().getColumn(7).setResizable(false);
     jTableempre.getColumnModel().getColumn(7).setPreferredWidth(110);
     jTableempre.getColumnModel().getColumn(8).setResizable(false);
     jTableempre.getColumnModel().getColumn(8).setPreferredWidth(110);

     jTableempre.getTableHeader().setReorderingAllowed(false);
     jTableempre.setAutoResizeMode(jTableempre.AUTO_RESIZE_OFF);
     jTableempre.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    }
    
    
    private void jButton1novoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1novoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1novoActionPerformed

    private void jTextFieldnomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldnomeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldnomeActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
      
        int resposta ;
        
        resposta=JOptionPane.showConfirmDialog(null, "Quer mesmo sair do programa?");       

       if (resposta == JOptionPane.YES_OPTION) {

dispose();



} else {


}
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jComboBox1funcoesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1funcoesActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBox1funcoesActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
         
        try {
            
            conectEmp.executaSQL("select * from empregados order by bi");
            conectEmp.re.first();
            
            jTextFieldbi.setText(String.valueOf(conectEmp.re.getInt("bi")));
            jTextFieldconselho.setText(conectEmp.re.getString("concelho"));
            jTextFieldnome.setText(conectEmp.re.getString("nome"));
            jTextFieldmorada.setText(conectEmp.re.getString("morada"));
            jTextFieldnacionalidade.setText(conectEmp.re.getString("nacionalidade"));
            jTextFieldestado.setText(conectEmp.re.getString("estadocivil"));
            jTextFieldpass.setText(conectEmp.re.getString("palavrapasse"));   
            jTextFieldlogin.setText(conectEmp.re.getString("login"));
            jTextFieldnrcont.setText(String.valueOf(conectEmp.re.getInt("nrcontribuinte")));         
            jTextFieldnsegsocial.setText(String.valueOf(conectEmp.re.getInt("segsocial")));         
          
            
            conect.executaSQL("select * from funcao where id_funcao ="+ conectEmp.re.getInt("funcao"));
            conect.re.first();
            jComboBox1funcoes.setSelectedItem(conect.re.getString("descricao"));
            
            
       } catch (SQLException ex) {
            Logger.getLogger(Empregados.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    
    
    
    private void jButton2ultimoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ultimoActionPerformed
 try {
            
            conectEmp.executaSQL("select * from empregados order by bi");
            conectEmp.re.last();
            
            jTextFieldbi.setText(String.valueOf(conectEmp.re.getInt("bi")));
            jTextFieldconselho.setText(conectEmp.re.getString("concelho"));
            jTextFieldnome.setText(conectEmp.re.getString("nome"));
            jTextFieldmorada.setText(conectEmp.re.getString("morada"));
            jTextFieldnacionalidade.setText(conectEmp.re.getString("nacionalidade"));
            jTextFieldestado.setText(conectEmp.re.getString("estadocivil"));
            jTextFieldpass.setText(conectEmp.re.getString("palavrapasse"));   
            jTextFieldlogin.setText(conectEmp.re.getString("login"));
            jTextFieldnrcont.setText(String.valueOf(conectEmp.re.getInt("nrcontribuinte")));         
            jTextFieldnsegsocial.setText(String.valueOf(conectEmp.re.getInt("segsocial")));         
          
            
            conect.executaSQL("select * from funcao where id_funcao ="+ conectEmp.re.getInt("funcao"));
            conect.re.first();
            jComboBox1funcoes.setSelectedItem(conect.re.getString("descricao"));
            
            
       } catch (SQLException ex) {
            Logger.getLogger(Empregados.class.getName()).log(Level.SEVERE, null, ex);
        }    }//GEN-LAST:event_jButton2ultimoActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton3ActionPerformed

    
    
    
    
    
    
    
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Empregados.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Empregados.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Empregados.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Empregados.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Empregados().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton1novo;
    private javax.swing.JButton jButton2guardar;
    private javax.swing.JButton jButton2ultimo;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JComboBox jComboBox1funcoes;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTable jTableempre;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextArea jTextArea2;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextFieldbi;
    private javax.swing.JTextField jTextFieldconselho;
    private javax.swing.JTextField jTextFieldestado;
    private javax.swing.JTextField jTextFieldlogin;
    private javax.swing.JTextField jTextFieldmorada;
    private javax.swing.JTextField jTextFieldnacionalidade;
    private javax.swing.JTextField jTextFieldnome;
    private javax.swing.JTextField jTextFieldnrcont;
    private javax.swing.JTextField jTextFieldnsegsocial;
    private javax.swing.JTextField jTextFieldpass;
    // End of variables declaration//GEN-END:variables
}
